if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SendNoticeQueueGetOneNewSite]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SendNoticeQueueGetOneNewSite]
GO

CREATE PROCEDURE dbo.[SendNoticeQueueGetOneNewSite]
(
	@NewSiteID uniqueidentifier
)
AS
SET NOCOUNT ON

DECLARE
	@SendNoticeQueueID int

SET @SendNoticeQueueID = (SELECT TOP 1 SendNoticeQueueID FROM SendNoticeQueue WHERE IsBeingProcessed = 0 AND NewSiteID = @NewSiteID)

UPDATE 
	SendNoticeQueue 
SET 
	IsBeingProcessed = 1
WHERE
	SendNoticeQueueID = @SendNoticeQueueID

SELECT
	TOP 1
	*
FROM
	SendNoticeQueue
WHERE
	SendNoticeQueueID = @SendNoticeQueueID
GO